Skip to content

Fix JSDoc @import crashes in getCompletionEntryDetails #62028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 9, 2025

The completion system was crashing when trying to get completion entry details for JSDoc @import statements. Consider:

/** @import * as t from './types.ts' */

import { preventDefault } from "./other-file.js";

p // <-- requesting completions here would crash

The error was:

Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isTypeKeywordToken'.

Root Cause:
The completion system tries to promote type-only imports to regular imports when they are used in value contexts. For JSDoc @import statements, this promotion logic incorrectly assumed the import had a type keyword that could be found and removed, but JSDoc imports don't have this structure - they are inherently type-only.

Solution:
Added a check in promoteImportClause function to skip type keyword deletion for JSDoc imports:

function promoteImportClause(importClause: ImportClause) {
    // JSDoc imports are inherently type-only and don't have a removable 'type' keyword
    if (!isJSDocImportTag(importClause.parent)) {
        changes.delete(sourceFile, getTypeKeywordOfTypeOnlyImport(importClause, sourceFile));
    }
    // ... rest of function
}

This allows JSDoc imports to be safely handled during the completion promotion process without attempting to remove a non-existent type keyword.

Fixes #62027.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Jul 9, 2025
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] JSDoc @import causes getCompletionEntryDetails to crash Fix JSDoc @import crashes in getCompletionEntryDetails Jul 9, 2025
@Copilot Copilot AI requested a review from RyanCavanaugh July 9, 2025 16:28
Copilot finished work on behalf of RyanCavanaugh July 9, 2025 16:28
Copy link

@louwers louwers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a regression test?

@louwers
Copy link

louwers commented Jul 9, 2025

Seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSDoc @import causes getCompletionEntryDetails to crash
4 participants